<!--  -->
<template>
  <div class="">
    <div class="cont">
      <div class="search">
        <img src="../../assets/images/home/search.png" alt="" />
        <input type="text" placeholder="请输入搜索内容" />
        <button class="btnsearch">搜索</button>
      </div>
      <div class="tabs">
        <p class="font30 fwbold ptb10">周边配件</p>
        <ul class="title">
          <li
            v-for="(item, index) in typelist"
            :key="index"
            @click="navchange(item, index)"
            :class="show == index ? 'active' : ''"
          >
            {{ item.name }}
          </li>
        </ul>
        <ul class="tab_con">
          <li
            @click="godetail(item)"
            class="choicenesstwo_details"
            v-for="item in list4"
            :key="item.id"
          >
            <img :src="item.image | imgSrc" alt="" />
            <p>{{ item.title }}</p>
          </li>
        </ul>
        <!-- <div class="page">
          <el-pagination background layout="prev, pager, next" :total="280">
          </el-pagination>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
import { peijiantype, peijianlist } from "@/utils/api";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      list4: [
        {
          id: 1,
          title: "精选白色手机钢化膜——iPhone15",
          img: require("../../assets/images/home/图层 11.png"),
        },
        {
          id: 2,
          title: "精选彩色手机链",
          img: require("../../assets/images/home/图层 12.png"),
        },
        {
          id: 3,
          title: "星星立体手机壳——iPhone15",
          img: require("../../assets/images/home/图层 13.png"),
        },
        {
          id: 4,
          title: "小熊饼干手机壳——iPhone15",
          img: require("../../assets/images/home/图层 14.png"),
        },
        {
          id: 5,
          title: "星星立体手机壳——iPhone15",
          img: require("../../assets/images/home/图层 13.png"),
        },
      ],
      show: 0,
      typelist: [],
      currentid: 0,
      title: "",
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    //获取分类列表
    gettypelist() {
      peijiantype().then((res) => {
        console.log("分类列表", res.data);
        this.typelist = res.data;
      });
    },
    navchange(item, index) {
      this.show = index;
      this.currentid = item.id;
    },
    // 获取列表
    getlist() {
      peijianlist(this.currentid, this.title).then((res) => {
        console.log(res);
        this.list4 = res.data.data;
      });
    },
    godetail(item) {
      this.$router.push({
        name: "pejiandetail",
        query: {
          goods_id: item.id,
        },
      });
    },
  },

  created() {
    this.gettypelist();
    this.getlist();
  },
};
</script>
<style lang="less" scoped>
.cont {
  margin: 0px 105px;
  display: flex;
  justify-content: center;
  flex-flow: row wrap;

  .search {
    width: 50%;
    height: 60px;
    background: #f9f9f9;
    border: 1px solid #f1f1f1;
    box-shadow: 0px 0px 10px 0px rgba(227, 227, 227, 0.41);
    border-radius: 30px;
    margin: 30px 0px;
    overflow: hidden;
    display: flex;
    align-items: center;

    img {
      width: 25px;
      height: 25px;
      margin-left: 10px;
    }

    input {
      width: 82%;
      height: 100%;
      outline: none;
      border: 0;
      background-color: transparent;
      text-indent: 2em;
      font-size: 20px;
      font-weight: 400;
      color: #999999;
    }

    .btnsearch {
      width: 15%;
      height: 54px;
      background: #ff5757;
      border-radius: 30px;
      // font-size: 20px;
      font-weight: 400;
      color: #ffffff;
      text-align: center;
      line-height: 54px;
      border: 0;
      outline: 0;
    }
  }

  .tabs {
    width: 100%;

    .title {
      display: flex;
      margin-top: 10px;

      li {
        width: 120px;
        height: 40px;
        background: #f9f9f9;
        border-radius: 20px;
        margin-right: 20px;
        font-size: 16px;
        font-weight: 400;
        color: #000;
        text-align: center;
        line-height: 40px;
      }

      .active {
        background: #ff5757;
        font-weight: bold;
        color: #fff;
      }
    }

    .tab_con {
      width: 100%;
      display: flex;
      flex-flow: row wrap;
      justify-content: space-between;
      margin: 20px 0px;

      li {
        width: 25%;
        margin-bottom: 20px;

        img {
          width: 100%;
          // height: 693px;
          margin-bottom: 20px;
        }

        p {
          font-size: 22px;
          font-weight: bold;
          color: #000000;
          text-align: center;
        }
      }
    }

    .page {
      width: 100%;
      display: flex;
      justify-content: center;
    }
  }
}
</style>
